package com.ruike.alisurface.ui.adv;

import android.view.View;

import androidx.fragment.app.Fragment;
import androidx.fragment.app.FragmentManager;
import androidx.fragment.app.FragmentTransaction;

import com.ruike.alisurface.Constant;
import com.ruike.alisurface.R;
import com.ruike.alisurface.base.BaseAty;
import com.ruike.alisurface.serialport.MsgEventBus;
import com.ruike.alisurface.ui.ShopMain_Aty;
import com.voodoo.lib_logcat.L;
import com.voodoo.lib_utils.SharedUtils;

import butterknife.OnClick;

/**
 * Author：voodoo
 * CreateTime：2021/06/17 017 上午 10:33
 * Description：广告界面
 */
public class Adv_Aty extends BaseAty {

    @Override
    protected int getLayoutResId() {
        return R.layout.activity_fgt_container;
    }

    @Override
    protected void initViews() {

    }

    @Override
    protected void initData() {
        int advType = SharedUtils.getInstance().getInt(Constant.AdvType.ADV_TYPE_KEY);
        switch (advType) {
            case Constant.AdvType.IMAVE:
                L.i("图片广告，加载图片广告Fragment");
                replaceFragment(new ImageAdvFragment());
                break;
            case Constant.AdvType.VIDEO:
                L.i("视频广告，加载视频广告Fragment");
                replaceFragment(new VideoAdvFragment());
                break;
        }
    }

    /**
     * 切换Fragment
     *
     * @param fragment 目标Fragment
     */
    public void replaceFragment(Fragment fragment) {
        FragmentManager fragmentManager = getSupportFragmentManager();
        FragmentTransaction transaction = fragmentManager.beginTransaction();
        transaction.replace(R.id.fgtContainer_content_flayout, fragment).commit();
    }

    public void jumpToProductListActivity() {
        startCountdownTimer(0, null, ShopMain_Aty.class);
    }

    @OnClick({R.id.fgContitle_moreClick_view})
    @Override
    public void onClick(View view) {
        super.onClick(view);
        // 多点击指令
        switch (view.getId()) {
            case R.id.fgContitle_moreClick_view:
                mroeClick();
                break;
        }
    }

    @Override
    public void onEventBusResult(MsgEventBus event) {
        super.onEventBusResult(event);
        if (event.getType().equals("adv_type")) {
            if (event.getMessage().equals("无广告")) {
                startActivity(ShopMain_Aty.class, null);
                finish();
                return;
            }
            if (event.getMessage().equals("图片样式")) {
                L.i("图片广告，加载图片广告Fragment");
                replaceFragment(new ImageAdvFragment());
                return;
            }
            if (event.getMessage().equals("视频样式")) {
                L.i("视频广告，加载视频广告Fragment");
                replaceFragment(new VideoAdvFragment());

            }
        }

    }
}
